<?php
/**
 * RMP助手
 * @author jianhui
 * 
 */
class Help extends MY_Controller{
    function Help(){
        parent::MY_Controller();
    }
    /**
     * 文件列表
     */
    function fileList(){
        $this->user['userRole'] == 6 || showError('您无权进入此页');
        $this->load->model('helperFileModel');
        $this->viewData['fileList'] = $this->helperFileModel->getList(array('userId'=>$this->user['userId']), null, null, '', 'id desc');
        $this->viewData['tab'] = 'fileList';
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('Helper', 'fileList'),'title'=>'RMP助手');
        $this->load->view('Help/fileList', $this->viewData);
    }
    /**
     * 文件添加或编辑文件
     */
    function fileAdd(){
        $this->user['userRole'] == 6 || showError('您无权进入此页');
        $this->load->model('helperFileModel');
        if ($_POST){
            $id = (int)$this->input->post('id');
            $data = array(
                'title' => $this->input->post('title'),
                'fileId' => (int)$this->input->post('fileId'),
                'userId' => $this->user['userId'],
                'userRole' => $this->user['userRole'],
            );
            $data['title'] || showError('请输入文件标题');
            $data['fileId'] || showError('请上传文件');
            if ($id){
                $id = $this->helperFileModel->edit($id, $data);
            }else{
                $data['createTime'] = time();
                $id = $this->helperFileModel->add($data);
            }
            if ($id){
                showSuccess('保存文件成功');
            }else{
                showError('保存文件失败');
            }
        }else{
            $id = (int)$this->input->get('id');
            if ($id){
                $this->viewData['fileData'] = $this->helperFileModel->getData($id);
                $this->viewData['fileData'] || showError('文件信息不存在');
            }
            $this->load->view('Help/fileAdd', $this->viewData);
        }
    }
    /**
     * 文件删除
     */
    function fileDel(){
        $this->user['userRole'] == 6 || showError('您无权进入此页');
        $id = (int)$this->input->post('id');
        $id || showError('请选择要删除的文件');
        $this->load->model('helperFileModel');
        if($this->helperFileModel->del($id)){
            showSuccess('删除文件成功');
        }else{
            showError('删除文件失败');
        }
    }
    /**
     * 文件列表查看
     */
    function fileCheck(){
        $this->load->model('helperFileModel');
        $this->viewData['fileList'] = $this->helperFileModel->getList(array('id > '=> 0), null, null, '', 'id desc');
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('Helper', 'fileCheck'),'title'=>'RMP助手');
        $this->load->view('Help/fileCheck', $this->viewData);
    }
    /**
     * 公告列表
     */
    function noticeList(){
        $this->user['userRole'] == 6 || showError('您无权进入此页');
        $this->load->model('helperNoticeModel');
        $this->viewData['noticeList'] = $this->helperNoticeModel->getNewList(array('userId'=>$this->user['userId']), null, null, '', 'id desc');
        $this->viewData['tab'] = 'noticeList';
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('Helper', 'noticeList'),'title'=>'RMP助手');
        $this->load->view('Help/noticeList', $this->viewData);
    }
    /**
     * 添加或修改公告
     */
    function noticeAdd() {
        $this->load->model('helperNoticeModel');
        if ($_POST){
            $id = (int)$this->input->post('id');
            $data = array(
                'title'     => $this->input->post('title'),
                'content'   => $this->input->post('content'),
                'displayRole' => (int)$this->input->post('displayRole'),
                'userId'    => $this->user['userId'],
                'userRole'  => $this->user['userRole'],
            );
            $data['title'] || showError('请输入公告标题');
            $data['content'] || showError('请输入公告内容');
            $data['displayRole'] || showError('请选择公告显示端口');
            if ($id){
                $id = $this->helperNoticeModel->edit($id, $data);
            }else{
                $data['createTime'] = time();
                $id = $this->helperNoticeModel->add($data);
            }
            if ($id){
                showSuccess('保存公告成功');
            }else{
                showError('保存公告失败');
            }
        }else{
            $id = (int)$this->input->get('id');
            if ($id){
                $this->viewData['noticeData'] = $this->helperNoticeModel->getData($id);
                $this->viewData['noticeData'] || showError('广告数据不存在');
            }
            $this->viewData['displayRole'] = $this->helperNoticeModel->getDisplayRole();
            $this->load->view('Help/noticeAdd', $this->viewData);
        }
    }
    /**
     * 公告查看
     */
    function noticeDel(){
        $this->user['userRole'] == 6 || showError('您无权进入此页');
        $id = (int)$this->input->post('id');
        $id || showError('请选择要删除的广告');
        $this->load->model('helperNoticeModel');
        if($this->helperNoticeModel->del($id)){
            showSuccess('删除广告成功');
        }else{
            showError('删除广告失败');
        }
    }
    /**
     * 公告查看
     */
    function noticeCheck() {
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('Helper', 'noticeCheck'),'title'=>'公告');
        $this->load->view('Help/noticeCheck', $this->viewData);
    }
}